package task;

public class Test5 {
    public static void main(String[] args) throws InterruptedException {
        Object lock1 = new Object();
        Object lock2 = new Object();
        Thread t1 = new Thread(() -> {
            synchronized (lock1){
                try {
                    lock1.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            Thread a = Thread.currentThread();
            System.out.println(a.getName());
        },"a");
        Thread t2 = new Thread(() -> {
            synchronized (lock2){
                try {
                    lock2.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            Thread b = Thread.currentThread();
            System.out.println(b.getName());
            synchronized (lock1){
                lock1.notify();
            }
        },"b");
        Thread t3 = new Thread(() -> {
            Thread c = Thread.currentThread();
            System.out.println(c.getName());
            synchronized (lock2){
                lock2.notify();
            }
        },"c");
        t1.start();
        t2.start();
        t3.start();
        t1.join();
        t2.join();
        t3.join();
    }
}
